library(tidyverse)
[37m-- [1mAttaching packages[22m --------------------------------------- tidyverse 1.2.1 --[39m
[37m[32mv[37m [34mggplot2[37m 3.1.0 [32mv[37m [34mpurrr [37m 0.2.5
[32mv[37m [34mtibble [37m 2.0.1 [32mv[37m [34mdplyr [37m 0.7.8
[32mv[37m [34mtidyr [37m 0.8.2 [32mv[37m [34mstringr[37m 1.3.1
[32mv[37m [34mreadr [37m 1.3.1 [32mv[37m [34mforcats[37m 0.3.0[39m
[37m-- [1mConflicts[22m ------------------------------------------ tidyverse_conflicts() --
[31mx[37m [34mdplyr[37m::[32mfilter()[37m masks [34mstats[37m::filter()
[31mx[37m [34mdplyr[37m::[32mlag()[37m masks [34mstats[37m::lag()[39m
library(plotly)
Attaching package: 㤼㸱plotly㤼㸲
The following object is masked from 㤼㸱package:ggplot2㤼㸲:
last_plot
The following object is masked from 㤼㸱package:stats㤼㸲:
filter
The following object is masked from 㤼㸱package:graphics㤼㸲:
layout
library(crosstalk)
take dplyr::starwars and mungin it into crostalk::SharedData
sw_eye <- starwars %>%
filter(eye_color == str_extract(eye_color, "\\w+")) %>%
filter(eye_color != "unknown", eye_color != "hazel", eye_color != "white") %>%
filter(mass < 200) %>%
mutate(eye_color = fct_infreq(eye_color)) %>%
mutate(species = fct_rev(fct_infreq(species)))
sw_eye_levels <- levels(sw_eye$eye_color)
shared_sw_eye <- SharedData$new(sw_eye)
vertbar <- ggplotly(shared_sw_eye %>%
ggplot(aes(eye_color)) +
geom_bar())
scatter <- plot_ly(data = shared_sw_eye, x = ~mass, y = ~height,
color = ~eye_color, colors = sw_eye_levels,
text = ~name, mode = "markers") %>%
layout(title = "\nStarWars Character Eye Color", height = 400)
Specifying width/height in layout() is now deprecated.
Please specify in ggplotly() or plot_ly()
horbar <- ggplotly(ggplot(shared_sw_eye, aes(x = species)) + geom_bar() + coord_flip())
subplot(vertbar, scatter)
No trace type specified:
Based on info supplied, a 'scatter' trace seems appropriate.
Read more about this trace type -> https://plot.ly/r/reference/#scatter
Can only have one: config
subplot(scatter, horbar, nrows = 2)
No trace type specified:
Based on info supplied, a 'scatter' trace seems appropriate.
Read more about this trace type -> https://plot.ly/r/reference/#scatter
Can only have one: config
Selection: Transient v persistent
sd <- SharedData$new(txhousing, ~city)
p <- ggplot(sd, aes(date, median)) + geom_line()
gg <- ggplotly(p, tooltip = "city")
# Persistent mode can still be enabled in this case by holding the
# shift key when hovering over lines
bscols(highlight(gg, on = "plotly_hover", dynamic = TRUE),
# Persistent mode can be set permanently like so
highlight(gg, on = "plotly_hover", dynamic = TRUE, persistent = TRUE))
Adding more colors to the selection color palette.
Adding more colors to the selection color palette.
We recommend setting `persistent` to `FALSE` (the default) because persistent selection mode can now be used by holding the shift key (while triggering the `on` event).
Setting the `off` event (i.e., 'plotly_doubleclick') to match the `on` event (i.e., 'plotly_hover'). You can change this default via the `highlight()` function.
Setting the `off` event (i.e., 'plotly_doubleclick') to match the `on` event (i.e., 'plotly_hover'). You can change this default via the `highlight()` function.
Setting the `off` event (i.e., 'plotly_doubleclick') to match the `on` event (i.e., 'plotly_hover'). You can change this default via the `highlight()` function.
Setting the `off` event (i.e., 'plotly_doubleclick') to match the `on` event (i.e., 'plotly_hover'). You can change this default via the `highlight()` function.